package com.xuexiang.xuidemo.ability;

import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;

import com.xuexiang.xui_lib.component.TitleBarLayout;

public abstract class BaseAbility extends BaseStatusAbility implements TitleBarLayout.ITitleBarClickListener {


    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        String mainRoute = getMainRoute();
        if (mainRoute != null && !"".equals(mainRoute)) {
            setMainRoute(mainRoute);
        }

        int titleBarId = getTitleBarId();
        if (titleBarId > 0) {
            TitleBarLayout titleBar = (TitleBarLayout) findComponentById(titleBarId);
            titleBar.setTitleClickListener(this);
        }
        initComponents();
    }

    protected void initComponents() {

    }

    protected String getMainRoute() {
        return null;
    }

    protected int getTitleBarId() {
        return -1;
    }

    @Override
    public void onClick(Component component, TitleBarLayout.ClickEventType type) {
        switch (type) {
            case LEFT_ICON_CLICK:
                terminateAbility();
                break;
            case RIGHT_ICON_CLICK:
                break;
            default:
                break;
        }
    }
}
